package com.mh.service;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.mh.entity.User;
import com.mh.jdbc.entity.RowMapper;
import com.mh.jdbc.exception.DAOException;
import com.mh.jdbc.util.JdbcDao;

public class UserService {
	public User login(String username,String password){
		User user = null;
		String sql = "select * from user where username= ? and password=?";
		try {
			user = JdbcDao.queryForObject(new RowMapper<User>() {
				public User mappingRow(ResultSet rs, int rownum) throws SQLException {
					User dbUser = new User();
					dbUser.setId(rs.getInt("id"));
					dbUser.setUsername(rs.getString("username"));
					dbUser.setPassword(rs.getString("password"));
					return dbUser;
				}
			}, sql, username,password);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return user;
	}
}
